// 1. 创建一个命令接口
interface Command {
    execute(): void;
}
// 2. 创建一个请求类
class Receiver {
    action(): void {
        console.log('请求已收到');
    }
}
// 3. 创建具体的命令类
class ConcreteCommand implements Command {
    private receiver: Receiver;
    constructor(receiver: Receiver) {
        this.receiver = receiver;
    }
    execute(): void {
        console.log('请求已发送');
        this.receiver.action();
    }
}
// 4. 创建一个请求者
class Invoker {
    private command: Command;
    constructor(command: Command) {
        this.command = command;
    }
    action(): void {
        this.command.execute();
    }
}
// 5. 使用
const receiver = new Receiver();
const command = new ConcreteCommand(receiver);
const invoker = new Invoker(command);
invoker.action();